package com.project.common.domain;


import lombok.Getter;
import lombok.Setter;

/**
 */
public class Result<T> {
    /**
     * 成功
     */
    public static final int SUCCESS = 200;
    /**
     * 失败
     */
    public static final int FAIL = 1;

    @Getter
    @Setter
    private int code = SUCCESS;
    @Getter
    @Setter
    private String message = "";
    @Getter
    @Setter
    private T data = null;

    public boolean isSuccess() {
        return code == SUCCESS;
    }

    public static final <T> Result<T> success() {
        return of(SUCCESS, "成功");
    }

    public static final <T> Result<T> success(String msg) {
        return of(SUCCESS, msg);
    }

    public static final <T> Result<T> success(T data) {
        return of(data, SUCCESS, null);
    }

    public static final <T> Result<T> success(T data, String msg) {
        return of(data, SUCCESS, msg);
    }

    public static final <T> Result<T> error(String msg) {
        return of(FAIL, msg);
    }

    public static final <T> Result<T> of(int code, String msg) {
        return of(null, code, msg);
    }

    public static final <T> Result<T> of(T data, int code, String msg) {
        return new Result<>(code, msg, data);
    }

    public Result() {
    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(T data, String message) {
        this.message = message;
        this.data = data;
    }

    public Result(String message) {
        this.message = message;
    }

    public Result(T data) {
        this.data = data;
    }
}
